package controllers;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class GenericConector{
	private static String url = "jdbc:mysql://localhost:3306/";    
    private static String driverName = "com.mysql.jdbc.Driver";   
    private static String username = "root";   
    private static String password = "ignacio";
    private static Connection con;
    private static Statement sta;
      
    private static void startConnection() {
        try {
            Class.forName(driverName);
            try {
                con = DriverManager.getConnection(url, username, password);
            } catch (SQLException ex) {
                System.out.println("Fallo la conexion con la base de datos"); 
            }
        } catch (ClassNotFoundException ex) {
            System.out.println("Driver not found."); 
        }
        
    }
    
    private static void startStatement() throws SQLException{
    	sta = con.createStatement();    	
    }
    
    public void ejecutar(String consulta) throws SQLException{
     	startConnection();
    	startStatement();
    	sta.executeUpdate(consulta);  	
    }
    
    
    public ResultSet getResultSet (String consulta) throws SQLException
    {
    	startConnection();
    	startStatement();
    	return sta.executeQuery(consulta);
    }
    
}
